﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	RuleExecutor.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common.Rules
{
	/// <summary>
	/// Rule executor
	/// </summary>
	public abstract class RuleExecutor
	{
		/// <summary>
		/// Rule context
		/// </summary>
		public RulesCtx Ctx { get; protected set; }

		/// <summary>
		/// Rule executor
		/// </summary>
		/// <param name="ctx">Rule context</param>
		protected RuleExecutor(RulesCtx ctx)
		{
			Ctx = ctx;
		}

		/// <summary>
		/// Apply rule's action
		/// </summary>
		public virtual bool ApplyRule<TRuleType>(TRuleType rule)
			where TRuleType : IRule
		{
			return ApplyAction(rule.Action);
		}

		/// <summary>
		/// Apply action
		/// </summary>
		public abstract bool ApplyAction<TRuleActionType>(TRuleActionType action)
			where TRuleActionType : IRuleAction;
	}
}